<template>
	<view class="index">



		<view class="news_box">
			<view class="news_list" v-for="item in news" @click="toDistribution(item)" :key="item.url">

				<image :src="item.icon" mode="widthFix"></image>
				<view>{{item.name}}</view>

			</view>
		</view>



		<view class="tui_box" @click="tui">退出登录</view>
		
		<u-popup :closeable="true" v-model="infoShow" mode="center" border-radius="14">
			<view class="dj_box">
				  <view>{{info.goods.name}}</view>
					   <view>{{info.user.nickname}}</view>
					    <view>{{info.user.mobile}}</view>
						 <view>领取时间:</view>
						 <view>{{info.createtime}}</view>
						 
						
						 
						 <view v-if="info.hx_status==1" class="hx_btn" @click="setHx">确认核销</view>
						 <view v-else class="hx_btn">礼品码已核销过</view>
			</view>
		</u-popup>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: {},
				news: [
					{
						icon: '/static/img/distribution_3.png',
						name: '核销订单',
						url: '/pages/hx/lists',
						type:1
					},					
					{
						icon: '/static/img/distribution_2.png',
						name: '扫码核销',
						url: '',
						type:2
					},

				],
				num: 0,
				infoShow:false,
				info:''
			}
		},
		onLoad() {

		},
		methods: {
			setHx(){
				let params = {
					id: this.info.id,
					token : uni.getStorageSync('hxToken')
				};
				this.$post(this.$api.hxMake,params,res=>{
					let {code,data,msg}=res.data;
					this.$Toast(msg);
					if(code==1){
						this.infoShow=false;
					}
				});
			},
			make(){
				let _=this;
			    uni.scanCode({
			    	onlyFromCamera: true,
			    	success: function(res) {
			    
			    		let data = res.result.split('?id=');
			    
			    		let params = {
			    			id: data[data.length - 1],
							token : uni.getStorageSync('hxToken')
			    		};
			    		_.$get(_.$api.hxInfo,params,res=>{
							let {code,data}=res.data;
							if(code==1){
								_.info=data;
								_.infoShow=true;
							}
						});
			    
			    	}
			    })	
			},
			tui() {
				this.$showModal('确认退出登录?', () => {
					uni.setStorageSync('hxToken', '');
					uni.switchTab({
						url: '/pages/tabar/user'
					})
				});
			},

			toDistribution(e) {
			    if(e.type==1){
					uni.navigateTo({
						url:e.url
					})
				}else{
					this.make();
				}
				
			},
			withdrawal() {
				uni.navigateTo({
					url: 'withdrawal'
				})
			},
		},
		onShow() {
			uni.removeStorageSync('bankCard')
			let _ = this;
		}
	}
</script>

<style scoped>
	.msg{
		width: 100%;
		text-align: center;
	}
	.hx_btn{
		width: 100%;
		background-color: #E34305;
		color:white;
		text-align: center;
		border-radius: 25rpx;
		height: 70rpx;
		line-height: 70rpx;
		margin-top: 30rpx;
	}
	.dj_box{
		box-sizing: border-box;
		padding: 60rpx 20rpx 20rpx 20rpx;
		width: 500rpx;
	}
	
	.index {
		min-height: 100vh;

	}

	

	.news_box {
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		width: 100%;
		box-sizing: border-box;
		padding: 30rpx;
		
	}

	.news_list {
		width: 33.3%;
		height: 156rpx;
		text-align: center;
		font-size: 30rpx;
		color: #333333;
	}

	.news_list image {
		width: 40%;
		border-radius: 10rpx;
		margin-bottom: 30rpx;
	}

	.index /deep/ .uni-navbar__header-btns-left {
		width: 120rpx;
	}

	.index .fixed-top {
		position: absolute;
		top: 0;
	}

	.index /deep/ .uni-navbar--border {
		border: none;
	}

	.tui_box {
		position: fixed;
		bottom: 55rpx;
		left: 10%;
		width: 80%;
		text-align: center;
		background-color: #E34305;
		box-sizing: border-box;
		padding: 20rpx;
		color: white;
		border-radius: 35rpx;
	}
</style>